package main

import (
	"log"
	"net/http"
	"os"
	"time"
)

// logger for print time cost request and response
// middleware - because func is first-class
// so we can use functional programming theory to solve the problem
var logger = log.New(os.Stdout, "", 0)

func hello(wr http.ResponseWriter, r *http.Request) {
	startTime := time.Now()
	wr.Write([]byte("hello"))
	timeElapsed := time.Since(startTime)
	logger.Println(timeElapsed)
}

func showInfo(wr http.ResponseWriter, r *http.Request) {
	startTime := time.Now()
	wr.Write([]byte("show info"))
	timeElapsed := time.Since(startTime)
	logger.Println(timeElapsed)
}

func main() {
	http.HandleFunc("/hello", hello)
	http.HandleFunc("/show-info", showInfo)
	err := http.ListenAndServe(":8088", nil)
	if err != nil {
		log.Fatal(err)
	}
}
